import request from '@/utils/request'
import { getToken } from '@/utils/auth'

// 查询工程项目列表
export function getProjectList(query) {
  return request({
    url: '/wxh-cloud-rest/rest/' + getToken() + '/project/queryAll',
    method: 'get',
    params: query
  })
}

// 查询工程项目详情
export function getProjectDetail(param) {
  return request({
    url: '/wxh-cloud-rest/rest/' + getToken() + '/project/queryById',
    method: 'get',
    params: param
  })
}

// 保存工程项目
export function saveProject(data) {
  return request({
    url: '/wxh-cloud-rest/rest/' + getToken() + '/project/save',
    method: 'post',
    headers: { 'Content-Type': 'multipart/form-data' },
    data
  })
}

// 保存工程工单
export function saveProjectOrder(data) {
  return request({
    url: '/wxh-cloud-rest/rest/' + getToken() + '/projectOrder/save',
    method: 'post',
    headers: { 'Content-Type': 'multipart/form-data' },
    data
  })
}

// 查询工程工单详情
export function getProjectOrderDetail(query) {
  return request({
    url: '/wxh-cloud-rest/rest/' + getToken() + '/projectOrder/queryById',
    method: 'get',
    params: query
  })
}

// 查询工程项目下的工单列表
export function getProjectOrderList(param) {
  return request({
    url: '/wxh-cloud-rest/rest/' + getToken() + '/projectOrder/queryByProjectNo',
    method: 'get',
    params: param
  })
}

// 完工工单
export function finishProjectOrder(data) {
  return request({
    url: '/wxh-cloud-rest/rest/' + getToken() + '/projectOrder/finish',
    method: 'post',
    headers: { 'Content-Type': 'multipart/form-data' },
    data
  })
}

// 查询项目履历
export function getProjectTrace(param) {
  return request({
    url: '/wxh-cloud-rest/rest/' + getToken() + '/projectTrace/queryByProjectNo',
    method: 'get',
    params: param
  })
}
// 新增项目履历
export function addProjectTrace(data) {
  console.log(data)
  return request({
    url: '/wxh-cloud-rest/rest/' + getToken() + '/projectTrace/add',
    method: 'post',
    headers: { 'content-type': 'multipart/form-data' },
    data
    // headers: {"Content-Type": "application/x-www-form-urlencoded"}
  })
}

// 查看结算信息
export function querysettlelist(id) {
  return request({
    url: '/wxh-cloud-rest/rest/' + getToken() + '/projectsettle/querysettlelist/' + id,
    method: 'get',
    params: null
  })
}

// 添加结算信息
export function addSettle(data, id) {
  return request({
    url: '/wxh-cloud-rest/rest/' + getToken() + '/projectsettle/addsettle/' + id,
    method: 'post',
    data
  })
}

// 查询可派单网点or师傅
export function assignableObject(data) {
  return request({
    url: '/wxh-cloud-rest/rest/' + getToken() + '/projectOrder/queryMaintainSite',
    method: 'get',
    params: data
  })
}

// 查询可派单网点or师傅
export function assignOrder(data) {
  return request({
    url: '/wxh-cloud-rest/rest/' + getToken() + '/projectOrder/allocate',
    method: 'post',
    headers: { 'Content-Type': 'multipart/form-data' },
    data
  })
}

// 删除项目
export function removeProject(id) {
  return request({
    url: '/wxh-cloud-rest/rest/' + getToken() + '/project/remove/' + id,
    method: 'get'
  })
}
// 删除项目工单
export function removeProjectOrder(id) {
  return request({
    url: '/wxh-cloud-rest/rest/' + getToken() + '/projectOrder/remove/' + id,
    method: 'get'
  })
}
